package com.atde._03_creational_design_patterns.prototype.deepclone;


/**
 * @BelongsProject: hsp_java_design_mode
 * @BelongsPackage: com.atde._03_creational_design_patterns.prototype.deepclone
 * @Author: Del
 * @CreateTime: 2025-06-17  18:40
 * @Description: 测试原型模式 深拷贝
 * @Version: 1.0
 */
public class Client {
    public static void main(String[] args) {
        DeepProtoType deepProtoType = new DeepProtoType();
        deepProtoType.name = "张三";
        deepProtoType.deepCloneableTarget = new DeepCloneableTarget("张三", "张三");

//        // 方式1 深拷贝
//        try {
//            DeepProtoType deepProtoType1 = (DeepProtoType) deepProtoType.clone();
//            System.out.println(deepProtoType.hashCode() == deepProtoType1.hashCode());
//        } catch (CloneNotSupportedException e) {
//            throw new RuntimeException(e);
//        }

        // 方式2 深拷贝
        DeepProtoType deepProtoType2 = (DeepProtoType) deepProtoType.deepClone();
        System.out.println(deepProtoType.hashCode() == deepProtoType2.hashCode());
    }
}
